<!DOCTYPE html>
<html>
<head>
<title></title> <@h.head />
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<form action="${path}/retail/save" id="fm" method="post" enctype="multipart/form-data" class="definewidth m20">
		<input type="hidden" value="${(retail.id)!0}" name="id">
		<div style="text-align: center;" id="errorMsg">${msg!}</div>
		<table class="table table-bordered table-hover definewidth m10">
			<tr>
				<td width="10%" class="tableleft">门店名<span class="required">*</span></td>
				<td><input type="text" name="name" value="${(retail.name)!}" datatype="*" nullmsg="请输入门店名！"/></td>
			</tr>
			<tr>
				<td class="tableleft">电话</td>
				<td><input type="text" name="telephone" value="${(retail.telephone)!}"/></td>
			</tr>
			<tr>
				<td class="tableleft">手机</td>
				<td><input type="text" name="mobile" value="${(retail.mobile)!}"/></td>
			</tr>
			<tr>
				<td class="tableleft">联系人</td>
				<td><input type="text" name="contacts" value="${(retail.contacts)!}"/></td>
			</tr>
			<tr>
				<td class="tableleft">区域<span class="required">*</span></td>
				<td>
					<select name="region" datatype="*" nullmsg="请选择区域">
						<#list retailRegion as dict>
							<option value="${dict.value}" <#if retail?? && (retail.region==dict.value)>selected</#if>>${dict.label}</option>
						</#list>
					</select>
				</td>
			</tr>
			<tr>
				<td class="tableleft">城市<span class="required">*</span></td>
				<td>
					<select name="area" datatype="*" nullmsg="请选择城市">
						<#list retailArea as dict>
							<option value="${dict.id}" <#if retail?? && (retail.area==dict.id)>selected</#if>>${dict.name}</option>
						</#list>
					</select>
				</td>
			</tr>
			<tr>
				<td class="tableleft">详细地址<span class="required">*</span></td>
				<td><textarea rows="3" cols="*" name="address"  datatype="*" nullmsg="请填写详细地址！">${(retail.address)!}</textarea></td>
			</tr>
			<tr>
				<td class="tableleft">地图坐标<span class="required">*</span></td>
				<td><input type="text" name="position" value="${(retail.longitude + ',' + retail.latitude )!}" datatype="*" nullmsg="请填写地图坐标！"/>
					<a href="http://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">获取坐标</a>
					<input type="hidden" name="longitude" value="${(retail.longitude)!}">
					<input type="hidden" name="latitude" value="${(retail.latitude)!}">
				</td>
			</tr>
			<tr>
				<td class="tableleft">
					<#if (imgOnePath)??>
						<a target="_blank" href="${imgOnePath!}">门店图</a>
						<input type="hidden" name="imgOne" value="${(retail.imgOne)!}"/>
					<#else>门店图</#if>
					<#if !(retail)??><span class="required">*</span></#if></td>
				<td><input type="file" name="imgOneFile" class="w210" accept="image/jpeg,image/png" <#if !(retail)??>datatype="*"</#if> nullmsg="请选择门店图！"/>
					<span class="tips">推荐510*320</span>
				</td>
			</tr>
			<tr>
				<td class="tableleft">
					<#if (imgTwoPath)??>
						<a target="_blank" href="${imgTwoPath!}">门店图</a>
						<input type="hidden" name="imgTwo" value="${(retail.imgTwo)!}"/>
						<a title="删除" class="delimg${(retail.imgTwo)!}" href="javascript:delImg('${(retail.id)!}','${(retail.imgTwo)!}')">
							<img src="${path}/static/image/delete.png">
						</a>
					<#else>门店图</#if>
				</td>
				<td><input type="file" name="imgTwoFile" accept="image/jpeg,image/png"/>
					<span class="tips">推荐510*320</span>
				</td>
			</tr>
			<tr>
				<td class="tableleft">
					<#if (imgThreePath)??>
						<a target="_blank" href="${imgThreePath!}">门店图</a>
						<input type="hidden" name="imgThree" value="${(retail.imgThree)!}"/>
						<a title="删除" class="delimg${(retail.imgThree)!}" href="javascript:delImg('${(retail.id)!}','${(retail.imgThree)!}')">
							<img src="${path}/static/image/delete.png">
						</a>
					<#else>门店图</#if>
				</td>
				<td><input type="file" name="imgThreeFile" accept="image/jpeg,image/png"/>
					<span class="tips">推荐510*320</span>
				</td>
			</tr>
			<tr>
				<td class="tableleft"></td>
				<td>
					<button type="submit" class="btn btn-primary" type="button">保存</button>
					&nbsp;&nbsp;
					<button type="button" class="btn btn-success" name="backid"
						id="backid">返回列表</button>
				</td>
			</tr>
		</table>
	</form>
	<@h.foot />
<script type="text/javascript">
	$(function() {
		$('#backid').click(function() {
			window.location.href = "${path}/retail/list";
		});
		
		$("input[name='position']").blur(function(){
			var value = $(this).val().trim();
			if(value != "" && value.indexOf(",") > 0){
				var arrs = value.split(",");
				$("[name=longitude]").val(arrs[0]);
				$("[name=latitude]").val(arrs[1]);
			} else {
				$(this).val("");
			}
		});
		
		$("[name='region']").change(function(){
			$.get("${path}/retailArea/get/" + $(this).val(), function(data) {
				$("[name='area']").empty();
				$(data).each(function(index,element){
					$("[name='area']").append("<option value='" + element.id + "'>" + element.name + "</option>");
				});
			})
		});
	});
	$("#fm").Validform({
		tiptype : 3,
		postonce : true
	});
	function delImg(id,fileId) {
		$.ajax({type:"post",
			   url : "${path}/retail/deleteImg",
			   data : {'id':id,'fileId':fileId},
			   dataType : "json",
			   success : function(result){
				   if (result.status == 0) {
					   $(".delimg" + fileId).parent().html($(".delimg" + fileId).parent().text());
				   } else {
					   alert(result.msg);
				   }
			   }
		});
	}
</script>
</body>
</html>